/**
 * 核验相关API接口
 * 创建时间：2025-09-11
 * 作者：开发团队
 * 目的：处理二维码核验相关请求
 */

import { httpRequest } from '@/utils/request'
import type {
  QrCodeVerificationRequest,
  QrCodeVerificationResponse,
  VerificationSubmitRequest,
  VerificationRecord,
  VerificationRecordsParams,
  TodayStatistics
} from '@/types/verification'
import type { PaginationResponse } from '@/types/common'

export const verificationApi = {
  /**
   * 二维码核验
   * :param verificationData: 二维码数据和门卫ID
   * :return: 核验结果和访客信息
   */
  verifyQrCode(verificationData: QrCodeVerificationRequest): Promise<QrCodeVerificationResponse> {
    return httpRequest.post('/verification/qr-code', verificationData)
  },

  /**
   * 提交核验结果
   * :param submitData: 核验结果数据
   * :return: 记录ID
   */
  submitVerification(submitData: VerificationSubmitRequest): Promise<{ record_id: number }> {
    return httpRequest.post('/verification/submit', submitData)
  },

  /**
   * 获取核验记录列表
   * :param params: 查询参数（日期、状态、分页等）
   * :return: 分页核验记录列表
   */
  getRecords(params?: VerificationRecordsParams): Promise<PaginationResponse<VerificationRecord>> {
    return httpRequest.get('/verification/records', { params })
  },

  /**
   * 获取核验记录详情
   * :param id: 记录ID
   * :return: 核验记录详细信息
   */
  getRecordDetail(id: number): Promise<VerificationRecord> {
    return httpRequest.get(`/verification/records/${id}`)
  },

  /**
   * 获取今日统计数据
   * :return: 今日核验统计信息
   */
  getTodayStatistics(): Promise<TodayStatistics> {
    return httpRequest.get('/verification/today-statistics')
  },

  /**
   * 导出核验记录
   * :param params: 导出参数
   * :param format: 导出格式（excel/pdf）
   * :return: 下载链接
   */
  exportRecords(params: VerificationRecordsParams, format: 'excel' | 'pdf' = 'excel'): Promise<{ download_url: string }> {
    return httpRequest.post('/verification/export', { ...params, format })
  }
}